package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.os.Bundle;
import android.widget.SeekBar;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityMagnifierBinding;
import stark.common.basic.utils.StkPermissionHelper;

public class MagnifierActivity extends BaseAc<ActivityMagnifierBinding> {


    @Override
    protected int onCreate() {
        return R.layout.activity_magnifier;
    }

    @Override
    protected void initView() {
        mDataBinding.ivMagnifierBack.setOnClickListener(v -> onBackPressed());
    }

    @Override
    protected void initData() {
        getPermission();
        //设置相机缩放 [0,1]
        mDataBinding.sbMagnifier.setMax(100);
        mDataBinding.sbMagnifier.setProgress(0);
        mDataBinding.sbMagnifier.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                float value = (float) progress / 100;
                mDataBinding.cameraView.setZoom(value);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }


    //获取权限
    private void getPermission() {
        StkPermissionHelper.permission(Manifest.permission.CAMERA).reqPermissionDesc(getString(R.string.get_camera_permission)).callback(new StkPermissionHelper.ACallback() {
            @Override
            public void onGranted() {
                initCameraView();
            }

        }).request();
    }

    private void initCameraView() {
        mDataBinding.cameraView.setLifecycleOwner(this);
        mDataBinding.cameraView.setRequestPermissions(false);
    }

}